//
//  FeedBackViewController.m
//  project
//
//  Created by 圆圆陈 on 2017/12/18.
//  Copyright © 2017年 黄建华. All rights reserved.
//

#import "FeedBackViewController.h"

@interface FeedBackViewController ()<UITextViewDelegate>
@property(nonatomic,strong)UITextView *textView;
@property(nonatomic,strong)UIButton *commitBtn;
@property(nonatomic,strong)UILabel *phoneLabel;
@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *StateView = [[UIView alloc] init];
    StateView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, 20);
    StateView.backgroundColor = BBIGSTATECOLOR;
    [self.view addSubview:StateView];
    
    UIView *naView = [[UIView alloc] init];
    naView.frame = CGRectMake(0, 20+FitSimpleIpx(0, 20), kSCREEN_WIDTH, 44);
    naView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:naView];
    
    UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(0, 20+FitSimpleIpx(0, 20),screenWidth, 44)];
    lable.textColor=[UIColor blackColor];
    lable.font=SNFONT(17);
    lable.textAlignment = NSTextAlignmentCenter;
    lable.text = HHH_Text(@"意见反馈");
    
    [self.view addSubview:lable];
    
    UIButton *leftButton = [[UIButton alloc] init];
    leftButton.frame = CGRectMake(5, 20+FitSimpleIpx(0, 20), 44, 44);
    [leftButton setImageNormal:@"进入"];
    [leftButton addTarget:self action:@selector(leftbuttonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:leftButton];
    
    _textView = [[UITextView alloc]initWithFrame:CGRectMake(FitW(10), 20+FitSimpleIpx(0, 20)+44+2+FitH(10), HHHWIDTH-FitW(20), HHHHEIGHT/3)];
    _textView.layer.cornerRadius = 10;
    _textView.clipsToBounds = YES;
    _textView.layer.borderColor = UIColorHEX(0xd8d8d8).CGColor;
    _textView.text = HHH_Text(@"请输入您要反馈的内容");
    _textView.delegate = self;
    _textView.textColor = UIColorHEX(0xa8a8a8);
    _textView.layer.borderWidth  = 1;
    [self.view addSubview:_textView];
    NSString* phoneModel = [NSString iphoneType];
    _phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(FitW(10), _textView.bottom+FitH(10), HHHWIDTH-FitW(20), 15)];
    _phoneLabel.textColor = [UIColor blackColor];
    _phoneLabel.textAlignment = NSTextAlignmentRight;
    _phoneLabel.text = phoneModel;
    [self.view addSubview:_phoneLabel];
    
    _commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _commitBtn.frame = CGRectMake(FitW(10), HHHHEIGHT-FitH(70), HHHWIDTH-FitW(20), FitH(50));
    [_commitBtn setTitleNormal:HHH_Text(@"提交")];
    [_commitBtn setTitleColorNormal:[UIColor whiteColor]];
    [_commitBtn setBackgroundColor:[UIColor blackColor]];
    [_commitBtn addTouchUpTarget:self action:@selector(commitMessage:)];
    [self.view addSubview:_commitBtn];
    
    UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped)];
    tapGr.cancelsTouchesInView = NO;
    [self.view addGestureRecognizer:tapGr];
    
    SNShadowView *shadowLine = [[SNShadowView alloc] init];
    shadowLine.frame = SNFRAME(0,20+FitSimpleIpx(0, 20) + 44, HHHWIDTH, 0);
    [shadowLine showWithType:1];
    [self.view addSubview:shadowLine];
}
- (void)viewTapped{
    [self.view endEditing:YES];
}
-(void)commitMessage:(UIButton *)sender{
    if (_textView.text.length==0||[_textView.text isEqualToString:HHH_Text(@"请输入您要反馈的内容")]) {
        SHOWMBProgressHUD(nil, SN_Text(@"请输入您要反馈的内容"), nil, NO, 2);
        return;
    }
    sender.enabled = NO;
    
    NSString *content = [NSString stringWithFormat:@"[苹果反馈/%@/%@][帐号:%@][用户ID:%@][设备名:%@][广播包:%ld][客户ID:%ld][固件版本:%ld][是否连接:%d][内容:%@]",_phoneLabel.text,[UIDevice currentDevice].systemVersion,SN_USER.loginAccount,SN_USER.user_id,KK_BLEModel.bleName,KK_BLEModel.bleAdvID,KK_BLEModel.bleCustomerID,KK_BLEModel.bleVersion,KK_BLEModel.isConnected,_textView.text];
    [SN_Net FeedBackWithContent:content Success:^(id object) {
        if (object[@"ret"] && [object[@"ret"] intValue] == 0) {
            SHOWMBProgressHUD(nil, SN_Text(@"反馈提交成功,感谢您的宝贵建议!"), nil, NO, 2);
            [self.navigationController popViewControllerAnimated:YES];
            [SN_Net feedBackUserLog];
        } else {
            SHOWMBProgressHUD(nil, HHH_Text(object[@"message"]), nil, NO, 2.0);
        }
        sender.enabled = YES;
    } fail:^(id object) {
        sender.enabled = YES;
    }];
}
- (void)leftbuttonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    if ([_textView.text isEqualToString:HHH_Text(@"请输入您要反馈的内容")]) {
         _textView.text =@"";
    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}



@end
